import requests
import config


class ConteractAPI:
    def __init__(self):
        self.url_upload_conteract = config.BASE_URL + "/api/common/upload"
        self.url_insert_conteract = config.BASE_URL + "/api/contract"
        self.url_select_conteract = config.BASE_URL + "/api/contract/list"
        self.url_delect_conteract = config.BASE_URL + "/api/contract/remove/{}"

    def upload_conteract(self, token, file_data):
        return requests.post(url=self.url_upload_conteract, files={"file": file_data}, headers={"Authorization": token})

    def insert_conteract(self, token, insert_conteract_data):
        return requests.post(url=self.url_insert_conteract, headers={"Authorization": token},
                             json=insert_conteract_data)

    def select_conteract(self, token,phone):
        return requests.get(url=self.url_select_conteract, headers={"Authorization": token},params=phone)

    def delect_conteract(self,id, token):
        return requests.delete(url=self.url_delect_conteract.format(id), headers={"Authorization": token})
